import React from 'react'
import { useDispatch } from 'react-redux';

const Input = () => {
    const dispatch = useDispatch();

    const addItem = (e) => {

        if (e.keyCode === 13) {
            console.log(e.target.value);
            dispatch({
                type: 'add_item',
                payload: {
                    val: e.target.value,
                    key: Date.now()

                }
            });
        }
    }
    return (
        <div>
            <input autoFocus="autoFocus" onKeyUp={addItem} />

        </div>
    )
}
export default Input
